using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Fungus;
using PixelCrushers.DialogueSystem;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem.Interactions;
using XFABManager;
using XFFSM;
using XFGameFramework;
using XFGameFramework.ScriptableObjectSystem;
public class FightInfo
{
    public int Distance = 1;
    public int Rounds = 0;
    private static FightInfo _instance;
    public static FightInfo Instance => _instance ??= new FightInfo();
    private FightInfo() { } // 私有构造函数
}
public class Fight_FtStart : FSMState
{
    #region 字段
    private XFGameFramework.Module module;
    private int enemyId = 1;
    public PlayerModel player;
    public EnemyModel enemy;

    FightInfo.Instance.Rounds = 0;
    FightInfo.Instance.Distance = 6;

    private FightUIController fightUIController => module.LoadController<FightUIController>();
    private EnemyController enemyController => module.LoadController<EnemyController>();
    private PlayerController playerController => module.LoadController<PlayerController>();
    private GameController gameController => module.LoadController<GameController>();

    #endregion
    public override void OnEnter()
    {
        base.OnEnter();
        Debug.Log("Fight_FtStart OnEnter");

        module = userData as XFGameFramework.Module;
        if (module == null) throw new System.Exception("userData is not Module");

        module.LoadPanel<FightPanel>();

        //获取玩家和敌人数据
        player = playerController.GetPlayerModel();
        enemy = module.GetModel<EnemyModel>();

        EventManager.TriggerEvent(EventConst.战斗开始);
        
        CheckFirstAttack();
    }

    private void CheckFirstAttack()
    {
        LogUtil.Log("enemy : {0} , player : {1}",enemy.Agility,player.Agility);
;       if (player.Agility >= enemy.Agility)
        {
            gameController.SetGameState(GameState.Fight_Player);
        }
        else
        {
            gameController.SetGameState(GameState.Fight_Enemy);
        }
    }

    public override void OnExit()
    {
        base.OnExit();
        
        fightUIController.UpdateAllText(player, enemy);
        fightUIController.UpdateHp(player.currentHp, enemy.currentHp);
    }
}
